package com.openwater.tools.math;

import android.util.FloatMath;

public class Vector3f {

    public float x;
    public float y;
    public float z;

    public Vector3f() {
        x = y = z = 0;
    }

    public Vector3f(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Vector3f(Vector3f val) {
        x = val.x;
        y = val.y;
        z = val.z;
    }

    public Vector3f set(Vector3f val) {
        return set(val.x, val.y, val.z);
    }

    public Vector3f set(float x, float y, float z) {
        this.x = x;
        this.y = y;
        this.z = z;
        return this;
    }

    public Vector3f add(Vector3f v) {
        x += v.x;
        y += v.y;
        z += v.z;
        return this;
    }

    public Vector3f subtraction(Vector3f v) {
        x -= v.x;
        y -= v.y;
        z -= v.z;
        return this;
    }

    public Vector3f multiply(float val) {
        x *= val;
        y *= val;
        z *= val;
        return this;
    }

    public Vector3f divide(float val) {
        x /= val;
        y /= val;
        z /= val;
        return this;
    }

    public float lenghtSquare() {
        return x * x + y * y + z * z;
    }

    public float lenght() {
        return FloatMath.sqrt(lenghtSquare());
    }
    
    public float[] toArray() {
        float[] array = { x, y, z };
        return array;
    }

    @Override
    public String toString() {
        return "Vector3f [x=" + x + ", y=" + y + ", z=" + z + "]";
    }
}
